package com.ExcelServer.controller;

import com.ExcelServer.common.Result;
import com.ExcelServer.pojo.form.add.AddDetailsForm;
import com.ExcelServer.pojo.form.add.CreateTableForm;
import com.ExcelServer.pojo.form.delete.DeleteDetailsForm;
import com.ExcelServer.pojo.form.update.UpdateDetailsForm;
import com.ExcelServer.pojo.form.update.UpdateTableForm;
import com.ExcelServer.pojo.query.TableNameQuery;
import com.ExcelServer.pojo.query.TableQuery;
import com.ExcelServer.service.impl.PerformanceTrendsServiceImpl;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/se/performance/info")
@Tag(name = "业绩动态表格",description = "在这里进行业绩的动他表格的生成、查询，搜索，查找等")
public class PerformanceController {
    @Autowired
    PerformanceTrendsServiceImpl performanceTrendsService;

    @Operation(summary = "动态创建表格",description = "tableHeader 是需要创建的表格各个表头，默认包含了教师id，业绩类型，和业绩的有效时间/次数")
    @PostMapping("/createTable")
    public Result createTable(@RequestBody CreateTableForm createTableForm) {
       return performanceTrendsService.createTable(createTableForm);
    }


    @Operation(summary = "修改某个创建的表格",description = "修改某个创建的表格" +
            "注意，这里的这个表头个数不能发生变化，否则会直接出错。修改的实际上是前端展示的内容，" +
            "而不是表结构，表结构在创建之后就不允许更改")
    @PostMapping("/updateTableInfo")
    public Result updateTableInfo(@RequestBody UpdateTableForm updateTableForm) {
        performanceTrendsService.updateTableInfo(updateTableForm);
        return Result.success("修改成功");
    }

    @Operation(summary = "获取动态创建表格的粗略信息",description = "获取动态创建表格的粗略信息")
    @PostMapping("/getTable")
    public Result getTable(@RequestBody TableNameQuery tableNameQuery) {
        return performanceTrendsService.getTable(tableNameQuery);
    }

    @Operation(summary = "获取表格详细信息",description = "根据id获取表格详细信息,id是getTable这里得到的，condition是getTable这里得到的property")
    @PostMapping("/getTableDetails")
    public Result getTableById(@RequestBody TableQuery tableQuery) {
        return performanceTrendsService.getTableDetails(tableQuery);
    }

    @Operation(summary = "修改某一个业绩表具体内容",description = "根据表格id 和表内id 去修改某一个具体内容")
    @PostMapping("/updateDetails")
    public Result updateDetails(@RequestBody UpdateDetailsForm updateDetailsForm) {
        return performanceTrendsService.updateDetails(updateDetailsForm);
    }

    @Operation(summary = "添加某一个业绩表具体内容",description = "根据表格id 添加某一个具体内容")
    @PostMapping("/addDetails")
    public Result addDetails(@RequestBody AddDetailsForm addDetailsForm) {
        return performanceTrendsService.addDetails(addDetailsForm);
    }

    @Operation(summary = "删除具体某个业绩表",description = "删除具体某个业绩表")
    @DeleteMapping("/deletePerformanceById/{tableId}")
    public Result deletePerformanceById(@PathVariable String tableId) {
        return performanceTrendsService.deletePerformanceById(tableId);
    }

    @Operation(summary = "删除具体某个业绩表内的某条业绩内容",description = "删除具体某个业绩表内的某条业绩内容")
    @DeleteMapping("/deletePerformanceDetailsById")
    public Result deletePerformanceDetailsById(@RequestBody DeleteDetailsForm deleteDetailsForm) {
        return performanceTrendsService.deletePerformanceDetailsById(deleteDetailsForm);
    }

}
